import { defineStore } from '@/config/pinia/index.ts';
import { useMenusStore } from '@/config/pinia/menus.store.ts';
import { useTabsStore } from '@/config/pinia/tabs.store.ts';
const menusStore = useMenusStore();
const tabsStore = useTabsStore();
export const useCommonStore = defineStore({
	id      : 'commonStore',
	state   : () => {
		return {
			// 动态异步自定义组件是否准备完毕
			dynamicAsyncCustomComponentIsReady : false as boolean,
			// 皮肤
			theme : localStorage.getItem('theme') as 'light' | 'dark'
		};
	},
	actions : {
		async emptyStore() {
			this.$reset();
			menusStore.$reset();
			tabsStore.$reset();
			// 清空浏览器会话内存中的数据
			sessionStorage.clear();
		},
		async triggerTheme() {
			if ('light' === this['theme']) {
				this['theme'] = 'dark';
			} else if ('dark' === this['theme']) {
				this['theme'] = 'light';
			} else {
				// 如果是第一次进入,在localStorage里暂时没有皮肤数据
				// 此时走这里
				this['theme'] = 'dark';
			}
		},
		async componentReady() {
			this['dynamicAsyncCustomComponentIsReady'] = true;
		}
	},
	getters : {
		getDynamicAsyncCustomComponentIsReady : (state) => state.dynamicAsyncCustomComponentIsReady,
		getTheme                              : (state) => state.theme
	}
});